﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.quest.Display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import com.greensock.*;
    import flash.filters.*;
    import Display.*;
    import Display.aswingui.*;
    import com.zynga.skelly.util.*;
    import com.greensock.easing.*;

    public class QuestOverlaySprite extends Sprite {

        private const EXPIRE:int = 5000;
        private const BOUNCE_DURATION:Number = 0.5;
        private const BOUNCE_DIST:int = 15;
        private const BOUNCE_START_X:int = 70;
        private const BOUNCE_Y:int = 35;
        private const ICON_RIGHT_MARGIN:int = 10;

        private var m_name:String;
        private var m_type:String;
        private var m_persist:Boolean;
        private var m_timer:Timer;
        protected var m_bgAsset:DisplayObject;
        protected var m_jw:JWindow;
        protected var m_mainPanel:JPanel;
        protected var m_bouncyTween:TimelineLite;
        protected var m_icon:DisplayObject;

        public function QuestOverlaySprite(_arg1:String, _arg2:Boolean, _arg3:String){
            this.m_name = _arg3;
            this.m_type = _arg1;
            this.m_persist = _arg2;
            this.m_icon = null;
            this.init();
            this.doBounce();
            this.startExpireTimer();
        }
        protected function init():void{
            this.m_jw = new JWindow(this);
            this.m_mainPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            this.m_bgAsset = (new EmbeddedArt.questNotifications_bg() as DisplayObject);
            this.m_mainPanel.setBackgroundDecorator(new AssetBackground(this.m_bgAsset));
            this.m_mainPanel.setPreferredHeight(this.m_bgAsset.height);
            this.m_mainPanel.setMinimumHeight(this.m_bgAsset.height);
            this.m_mainPanel.setMaximumHeight(this.m_bgAsset.height);
            var _local1:XML = Global.gameSettings.getIconXMLByName(("questNotification_" + this.m_type));
            if (_local1){
                LoadingManager.load(Global.getAssetURL(_local1.image[0].asset.@url), this.onIconLoaded);
            } else {
                this.prepareWindow();
            };
            this.x = this.BOUNCE_START_X;
            this.y = (this.BOUNCE_Y - (this.m_bgAsset.height / 2));
        }
        protected function onIconLoaded(_arg1:Event):void{
            var _local2:Loader = (_arg1.target.loader as Loader);
            this.m_icon = (_local2 as DisplayObject);
            this.prepareWindow();
        }
        protected function prepareWindow():void{
            this.m_mainPanel.appendAll(ASwingHelper.verticalStrut(2), this.makeTextPanel());
            this.m_jw.setContentPane(this.m_mainPanel);
            ASwingHelper.prepare(this.m_mainPanel);
            ASwingHelper.prepare(this.m_jw);
            ASwingHelper.prepare(this);
            this.m_jw.show();
            if (this.m_icon){
                this.addChild(this.m_icon);
                this.m_icon.x = ((this.m_jw.width - this.m_icon.width) - this.ICON_RIGHT_MARGIN);
                this.m_icon.y = (-((this.m_icon.height - this.m_jw.height)) / 2);
            };
        }
        protected function makeTextPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel();
            var _local2:String = ZLoc.t("Quest", ("Notification_" + this.m_type));
            var _local3:Number = TextFieldUtil.getLocaleFontSize(24, 18, null);
            var _local4:JLabel = ASwingHelper.makeLabel(_local2, EmbeddedArt.TITLE_FONT, _local3, EmbeddedArt.whiteTextColor);
            _local4.setTextFilters([new DropShadowFilter(4, 45, EmbeddedArt.blackTextColor, 0.4, 2, 2)]);
            if (Global.localizer.langCode != "en"){
                _local1.appendAll(ASwingHelper.verticalStrut(35));
                _local1.appendAll(ASwingHelper.horizontalStrut(20), _local4, ASwingHelper.horizontalStrut(10));
            } else {
                _local1.appendAll(ASwingHelper.horizontalStrut(35), _local4, ASwingHelper.horizontalStrut(20));
            };
            if (this.m_icon){
                _local1.append(ASwingHelper.horizontalStrut(this.m_icon.width));
            };
            return (_local1);
        }
        protected function startExpireTimer():void{
            if (!this.m_persist){
                this.m_timer = new Timer(this.EXPIRE, 0);
                this.m_timer.addEventListener(TimerEvent.TIMER, this.expireTimeReached);
                this.m_timer.start();
            };
        }
        public function remove():void{
            this.cleanUp(false);
            TweenLite.to(this, 0.5, {
                alpha:0,
                onComplete:Curry.curry(function (_arg1:QuestOverlaySprite):void{
                    removeDisplayObject();
                    Global.hud.cleanUpBanner(_arg1);
                }, this)
            });
        }
        public function cleanUp(_arg1:Boolean=true):void{
            if (this.m_timer){
                this.m_timer.removeEventListener(TimerEvent.TIMER, this.expireTimeReached);
            };
            if (this.m_bouncyTween){
                this.m_bouncyTween.clear();
                this.m_bouncyTween.kill();
                this.m_bouncyTween = null;
            };
            TweenLite.killTweensOf(this);
            if (_arg1){
                this.removeDisplayObject();
            };
        }
        private function removeDisplayObject():void{
            if (this.parent){
                this.parent.removeChild(this);
            };
        }
        protected function expireTimeReached(_arg1:TimerEvent):void{
            Global.hud.removeBanner(this.m_name);
        }
        protected function doBounce(... _args):void{
            if (this.m_bouncyTween != null){
                this.m_bouncyTween.clear();
                this.m_bouncyTween.kill();
                this.m_bouncyTween = null;
            };
            if (Global.world.defCon > GameWorld.DEFCON_LEVEL1){
                return;
            };
            this.m_bouncyTween = new TimelineLite({onComplete:this.doBounce});
            this.m_bouncyTween.appendMultiple([new Z_TweenLite(this, this.BOUNCE_DURATION, {
                x:(this.BOUNCE_START_X + this.BOUNCE_DIST),
                ease:Quad.easeInOut
            }), new Z_TweenLite(this, this.BOUNCE_DURATION, {
                x:this.BOUNCE_START_X,
                ease:Quad.easeInOut
            })], 0, TweenAlign.SEQUENCE);
            this.m_bouncyTween.gotoAndPlay(0);
        }
        public function get persists():Boolean{
            return (this.m_persist);
        }

    }
}//package Modules.quest.Display 
